package cn.com.customer.manager.ui.edit

import cn.com.customer.manager.bean.User
import cn.com.customer.manager.manager.TokenManager
import com.xuexiang.xhttp2.XHttp
import com.xuexiang.xhttp2.subsciber.ProgressLoadingSubscriber
import com.xuexiang.xutil.file.FileUtils

class EditInfoPresenter constructor(val view: EditInfoContract.View) : EditInfoContract.Presenter {
    private var mView = view

    init {
        mView.setPresenter(this)
    }

    override fun modifyInfo(user: User,filePath:String) {
        XHttp.post("usr/modify")
                .keepJson(true)
                .params("token", TokenManager.getInstance().token)
                .params("name",user.name)
                .params("sex",user.sex)
                .params("email",user.email)
                .params("telephone",user.telephone)
                .params("mobile",user.mobile)
                .uploadFile("file", FileUtils.getFileByPath(filePath)
                ) { bytesWritten, contentLength, done ->

                }.execute(String::class.java)
                .subscribeWith(object : ProgressLoadingSubscriber<String>() {
                    override fun onSuccess(t: String?) {
                      mView.modifySuccess()
                    }

                });
    }

    override fun start() {
    }

}